package com.winning.sx.microframework.common.config;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.annotation.PostConstruct;

@Slf4j
@Configuration
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FreemarkerConfig {


    @Autowired
    private freemarker.template.Configuration configuration;

    private InternalResourceViewResolver resourceViewResolver;

    @Value("${system.name}")
    private String systemName;

    @Value("${system.layout}")
    private String systemLayout;

    @Value("${system.style}")
    private String systemStyle;

    @Value("${system.comName}")
    private String systemComName;
    @Value("${system.deptName}")
    private String systemDeptName;
    @Value("${system.icon}")
    private String systemIcon;
    @Value("${system.bg}")
    private String systemBg;
    @Value("${system.bgAdmin}")
    private String systemBgAdmin;

    /**
     * Spring 初始化的时候加载配置
     */
    @PostConstruct
    public void setConfigure() throws Exception {

        // 加载html的资源路径
        configuration.setSharedVariable("systemName", systemName);
        configuration.setSharedVariable("systemLayout", systemLayout);
        configuration.setSharedVariable("systemStyle", systemStyle);
        configuration.setSharedVariable("systemComName", systemComName);
        configuration.setSharedVariable("systemDeptName", systemDeptName);
        configuration.setSharedVariable("systemIcon", systemIcon);
        configuration.setSharedVariable("systemBg", systemBg);
        configuration.setSharedVariable("systemBgAdmin", systemBgAdmin);
    }


}
